package com.ysd.lis.controller.bac;


import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.bac.BacWorkFlow;
import com.ysd.lis.entity.bac.BacWorkFlowNodeDict;
import com.ysd.lis.request.BacWorkFlowDto;
import com.ysd.lis.service.bac.BacWorkFlowNodeDictService;
import com.ysd.lis.service.bac.BacWorkFlowService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 流程设定主表 前端控制器
 * </p>
 *
 * @author cfz
 * @since 2024-04-09
 */
@RestController
@RequestMapping("/api/bac/bac-work-flow")
public class BacWorkFlowController extends BaseController {
    @Autowired
    BacWorkFlowService bacWorkFlowService;
    @Autowired
    BacWorkFlowNodeDictService bacWorkFlowNodeDictService;

    @ApiOperation("查询")
    @GetMapping("/findBacWorkFlowList")
    public Result findBacWorkFlowList(BacWorkFlow bacWorkFlow) {
        return bacWorkFlowService.findBacWorkFlowList(bacWorkFlow);
    }

    @ApiOperation("增加")
    @PostMapping("/addBacWorkFlow")
    public Result addBacWorkFlow(@RequestBody BacWorkFlowDto bacWorkFlows) {
        boolean b = bacWorkFlowService.saveOrUpdateBatch(bacWorkFlows.getBacWorkFlows());
        if(b){
            return Result.succ("修改成功！");
        }
        return Result.fail("修改失败!");
    }

    @ApiOperation("删除")
    @PostMapping("/deleteBacWorkFlow")
    public Result deleteBacWorkFlow(@RequestBody BacWorkFlowDto bacWorkFlows) {
        List<String> collect = bacWorkFlows.getBacWorkFlows().stream().map(BacWorkFlow::getId).collect(Collectors.toList());
        boolean b = bacWorkFlowService.removeByIds(collect);
        if(b){
            return Result.succ("删除成功！");
        }
        return Result.fail("删除失败！");
    }

    @ApiOperation("修改")
    @PostMapping("/updateBacWorkFlow")
    public Result updateBacWorkFlow(@RequestBody BacWorkFlow bacWorkFlow) {
        return bacWorkFlowService.updateBacWorkFlow(bacWorkFlow);
    }

    @ApiOperation("查询")
    @GetMapping("/findBacWorkFlowNodeDictList")
    public Result findBacWorkFlowNodeDictList(String settingId) {
        return bacWorkFlowService.selectProsettingNode(settingId);
    }

}
